﻿// -----------------------------------------------------------------------
// <copyright file="BusinessLogicExceptionHandler.cs" company="EPAM Systems">
////Copyright (c) EPAM Systems, 2012. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace MBOP.Helpers.ExceptionHandling.ExceptionHandlers
{
	#region Usings

	using System;

	using MBOP.Helpers.ExceptionHandling.Exceptions;
	using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

	#endregion

	/// <summary>
	/// Business logic exception handler.
	/// </summary>
	public static class BusinessLogicExceptionHandler
	{
		#region Constants

		/// <summary>
		/// Represents policy name of the business logic.
		/// </summary>
		private const string POLICY_BUSINESS_LOGIC = "BusinessLogicPolicy";

		/// <summary>
		/// Represents policy name of the pass through policy.
		/// </summary>
		private const string POLICY_PASS_THROUGH = "PassThroughPolicy";

		#endregion

		/// <summary>
		/// Handles the business logic's exceptions. Handling depends on policies.
		/// </summary>
		/// <param name="ex">Occurred exception.</param>
		/// <returns>Indicates that the exception rethrow or not.</returns>
		public static bool HandleException(Exception ex)
		{
			bool rethrow = false;

			if (ex is DataAccessException)
			{
				rethrow = ExceptionPolicy.HandleException(ex, POLICY_PASS_THROUGH);
			}
			else
			{
				rethrow = ExceptionPolicy.HandleException(ex, POLICY_BUSINESS_LOGIC);
			}

			return rethrow;
		}
	}
}
